<?php
include("funciones/setup.php");
conecta();

session_start();

if(isset($_SESSION['sesion_usuario']))
{
	$id=$_GET['id'];
	if(isset($id))
	{
		$sql="select * from vendedor where id_ven=".$id;
		$reg=mysql_query($sql);
		$datos=mysql_fetch_array($reg);
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Formulario de Vendedores</title>
<link href="css/estilos_forms.css" rel="stylesheet" type="text/css" />
<link href="css/kendo.common.css" rel="stylesheet"/>
<link href="css/kendo.default.css" rel="stylesheet"/>
<link rel="stylesheet" type="text/css" href="css/paginador_busqueda.css"/>

<script src="js/jquery-1.7.1.js" language="javascript" type="text/javascript"></script>
<script src="js/vendedor.js" language="javascript" type="text/javascript"></script>
<script src="js/kendo.core.js" language="javascript" type="text/javascript"></script>
<script src="js/kendo.numerictextbox.js" language="javascript" type="text/javascript"></script>
<script src="js/kendo.validator.js" language="javascript" type="text/javascript"></script>
<script src="js/kendo.combobox.js" language="javascript" type="text/javascript"></script>
<script src="ajaxfileupload.js" language="javascript" type="text/javascript"></script>

<script src="js/jquery.Rut.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
function lookup(inputString) {
		if(inputString.length == 0) {
			$('#suggestions').hide();
		} else {
			$.post("busqueda_proveedores.php", {queryString: ""+inputString+""}, function(data){
				if(data.length >0) {
					$('#suggestions').show();
					$('#autoSuggestionsList').html(data);
				}
			});
		}
	} // lookup
	
	function fill(thisValue,thisValue2) {
		$('#frm_producto').val(thisValue2);
		$("#id_producto").val(thisValue);
		setTimeout("$('#suggestions').hide();", 200);
	}
			
</script>
<style type="text/css">
	.suggestionsBox {
		position: relative;
		left: 30px;
		margin: 10px 0px 0px 0px;
		width: 200px;
		background-color: #212427;
		-moz-border-radius: 7px;
		-webkit-border-radius: 7px;
		border: 2px solid #000;	
		color: #fff;
	}
	
	.suggestionList {
		margin: 0px;
		padding: 0px;
	}
	
	.suggestionList li {
		
		margin: 0px 0px 3px 0px;
		list-style-type:none;
		padding: 3px;
		cursor: pointer;
	}
	
	.suggestionList li:hover {
		background-color: #659CD8;
	}
</style>
<link href="css/estilos_base.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td><div id="credenciales">
      <table width="100%" border="0" cellspacing="3" cellpadding="0">
        <tr>
          <td width="42"><img src="imagenes/iconos/credenciales.png" width="42" height="28" /></td>
          <td class="fuente_normal">Bienvenido : <?php echo $_SESSION['sesion_usuario'];?></td>
        </tr>
        <tr>
          <td colspan="2"><table border="0" align="center" cellpadding="0" cellspacing="3">
            <tr>
              <td><a href="cerrar_sesion.php"><img src="imagenes/iconos/salir_session.png" width="22" height="23" border="0" /></a></td>
              <td class="fuente_normal"><a href="cerrar_sesion.php">Cerrar Sessión</a></td>
              <td class="fuente_normal">|</td>
              <td class="fuente_normal"><a href="panel_principal.php"><img src="imagenes/iconos/ico_panel_principal.png" width="22" height="23" border="0" /></a></td>
              <td class="fuente_normal"><a href="panel_principal.php">Panel Principal</a></td>
            </tr>
          </table></td>
        </tr>
      </table>
    </div></td>
    <td><div id="logotipo"><img src="imagenes/logo.png" width="200" height="82" /></div></td>
    <td><table border="0" align="right" cellpadding="0" cellspacing="5">
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><span class="fuente_login">La Serena, <?php echo fecha_hoy_mas_dia();?>&nbsp;</span></td>
      </tr>
    </table></td>
  </tr>
</table>
<br />
<div id="modulo">
  <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
    <table border="0" align="center" cellpadding="0" cellspacing="10">
      <tr>
        <td width="118" class="fuente_formularios">Rut :</td>
        <td width="341" class="fuente_formularios"><input name="frm_codigo" type="text" class="k-textbox" id="frm_codigo" value="<?php echo $datos['rut_ven'];?>" onblur="consulta_rut()" placeholder="Ingrese Rut" required/></td>
        <td width="27" class="fuente_formularios">&nbsp;</td>
        <td width="57" class="fuente_formularios">&nbsp;</td>
      </tr>
      <tr class="fuente_formularios">
        <td>Nombre Vendedor :</td>
        <td colspan="3"><input name="frm_nombre" type="text" class="k-textbox" id="frm_nombre" value="<?php echo $datos['nombre_ven'];?>" size="70" placeholder="Ingrese Nombre Completo" required/></td>
      </tr>
      <tr>
        <td class="fuente_formularios">Correo Vendedor :</td>
        <td colspan="2" class="fuente_formularios"><input name="frm_correo" type="text" id="frm_correo" class="k-textbox" value="<?php echo $datos['correo_ven'];?>" size="30" placeholder="Ingrese Correo Electrónico" required /></td>
        <td class="fuente_formularios">&nbsp;</td>
      </tr>
      <tr>
        <td class="fuente_formularios">Telefono</td>
        <td colspan="2" class="fuente_formularios"><input name="frm_telefono" type="text" id="frm_telefono" class="k-textbox" value="<?php echo $datos['telefono'];?>" size="30"placeholder="Ingrese Teléfono" required  /></td>
        <td class="fuente_formularios">&nbsp;</td>
      </tr>
      <?php if(isset($id)){
		  if($datos['arch_foto']==""){
		   ?>
      <tr>
        <td class="fuente_formularios">Cargar Fotografia :</td>
        <td colspan="2" class="fuente_formularios"><label for="file_foto1"></label>
        <input type="file" name="file_foto1" id="file_foto1" />
        <img id="loading" src="imagenes/loading2.gif" style="display:none;"><input type="button" name="button" id="button" value="Cargar" onclick="SubirImagen(<?php echo $id; ?>)" /></td>
        <td class="fuente_formularios">&nbsp;</td>
      </tr>
      <?php } else { ?>
      <tr>
        <td valign="top" class="fuente_formularios">Imagen :</td>
        <td colspan="2" class="fuente_formularios"><table border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><img src="archivos/<?php echo $datos['arch_foto']; ?>" width="150" /></td>
              <td><a href="#" onclick="elimina_imagen(<?php echo $id; ?>)"><img src="imagenes/iconos/ico16_borrar.gif" width="16" height="16" /></a></td>
            </tr>
        </table></td>
        <td class="fuente_formularios">&nbsp;</td>
      </tr>
     <?php }
	 	} 
		if(isset($id)){ ?>
      <tr class="fuente_formularios">
        <td>Elegir Proveedores :</td>
        <td><input name="frm_producto" type="text" class="k-textbox" id="frm_producto"  size="50" onkeyup="lookup(this.value);" onblur="fill();" placeholder="Buscar Proveedores" required/>
        <input type="hidden" name="id_producto" id="id_producto" />
        <div class="suggestionsBox" id="suggestions" style="display: none;">
			  <img src="imagenes/upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
    <div class="suggestionList" id="autoSuggestionsList">
    		&nbsp;
			</div>
        </div></td>
        <td><input type="button" name="btn_addproducto" id="btn_addproducto" value="+" class="k-button"/></td>
      </tr>
      <?php }?>
      <tr>
        <td colspan="5"><div id="proveedores"></div></td>
      </tr>
      <tr>
        <td colspan="4"><center>
          <label for="oculto_id"></label>
          <input type="hidden" name="id_oculto" id="id_oculto" value="<?php echo $id;?>" />
          <?php
		    if(!isset($id))
			{
				?>
            <input type="button" name="btn_ingresar" id="btn_ingresar" value="Ingresar" class="k-button"/> 
            &nbsp;
            <?php
			}
			else
			{?>
            <input type="button" name="btn_modificar" id="btn_modificar" value="Modificar" class="k-button"/>
            &nbsp;
			<input type="button" name="btn_elimina" id="btn_elimina" value="Eliminar" class="k-button"/>
            &nbsp;
            <?php
			}
			?>
<input type="button" name="btn_cancelar" id="btn_cancelar" value="Cancelar" class="k-button"/>
        </center></td>
      </tr>
    </table>
  </form>
</div>
<br />
<div id="paginador"></div>

<script language="javascript">

$(document).ready(function(){
	$("#proveedores").hide();
	$("#btn_ingresar").click(function(){
		validar(1);
	});
	$("#btn_modificar").click(function(){
		validar(2);
	});
	$("#btn_elimina").click(function(){
		elimina();
	});
	//elimina
	$("#btn_cancelar").click(function(){
		location.href="vendedores.php";
	});
	$("#btn_addproducto").click(function(){
		agregar_proveed();
	});
	$("#paginador").html(muestra_grilla());
	
	$('#frm_codigo').Rut(
	{
  		on_error: function(){ 
		     alert('Rut incorrecto'); 
			 $('#frm_codigo').val("");
			 $('#frm_codigo').focus();
	}
	});
		$("#proveedores").html(muestra_grilla_proveedor(<?php echo $id; ?>));
  	<?php  if(isset($id)){ ?>$("#proveedores").show();<?php } ?>
	
});

</script>

</body>
</html>
<?php
}
else
{
	header("Location:index.php");
}
?>